//
//  LJVideoNetStatusView.m
//  LajinLive
//
//  Created by 刘洋 on 2016/11/1.
//  Copyright © 2016年 lajin. All rights reserved.
//

#import "LJVideoNetStatusView.h"

@interface LJVideoNetStatusView()
@property (nonatomic, strong) UILabel *netStatustipsLabel;
@property (nonatomic, strong) UIButton *netStatusbtn;
@end

@implementation LJVideoNetStatusView
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI
{
    [self addSubview:self.netStatustipsLabel];
    [self addSubview:self.netStatusbtn];
    
    [self setContraint];
}

- (void)setContraint
{
    [self.netStatustipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(14);
        make.centerX.mas_equalTo(self.mas_centerX);
        make.centerY.mas_equalTo(self.mas_centerY).mas_offset(-20);
    }];
    
    [self.netStatusbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.netStatustipsLabel.mas_bottom).mas_offset(19);
        make.width.mas_equalTo(130);
        make.height.mas_equalTo(32);
        make.centerX.mas_equalTo(self.netStatustipsLabel.mas_centerX);
    }];
}

- (UILabel *)netStatustipsLabel
{
    if (!_netStatustipsLabel) {
        _netStatustipsLabel = [[UILabel alloc] init];
        _netStatustipsLabel.textColor = [UIColor whiteColor];
        _netStatustipsLabel.font = [UIFont systemFontOfSize:16.0];
        _netStatustipsLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _netStatustipsLabel;
}

- (UIButton *)netStatusbtn
{
    if (!_netStatusbtn) {
        _netStatusbtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _netStatusbtn.titleLabel.font = [UIFont systemFontOfSize:13.0f];
        _netStatusbtn.layer.borderWidth = 1.0;
        _netStatusbtn.layer.cornerRadius = 15;
        _netStatusbtn.layer.borderColor = [UIColor whiteColor].CGColor;
        [_netStatusbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_netStatusbtn setTitleColor:[UIColor colorWithWhite:1.0 alpha:0.1] forState:UIControlStateHighlighted];
        [_netStatusbtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _netStatusbtn;
}

- (void)setNetStatusTips:(NSString *)netStatusTips
{
    if (_netStatusTips == netStatusTips) {
        return;
    }
    _netStatusTips = netStatusTips;
    _netStatustipsLabel.text = _netStatusTips;
}

- (void)setNetStatusBtnTitle:(NSString *)netStatusBtnTitle
{
    if (_netStatusBtnTitle == netStatusBtnTitle) {
        return;
    }
    _netStatusBtnTitle = netStatusBtnTitle;
    [_netStatusbtn setTitle:_netStatusBtnTitle forState:UIControlStateNormal];
}

- (void)btnAction:(UIButton *)sender
{
    if (self.btnActionBlock) {
        self.btnActionBlock();
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
